# include coefficients

## twitter lexicoder
cx <- c %>% 
  filter(immigration > 0)
cx$treat[cx$date > -1] <- 1
cx$treat[cx$date < 0] <- 0
table(cx$treat)
twitlex <- lm(sentiment ~ treat, data = cx)
twitlex <- summary(twitlex)

# with politician fixed effects
twitlexfix <- lm(sentiment ~ treat + username, data = cx)
twitlexfix <- summary(twitlexfix)

twitlexC <- twitlex$coefficients[2,1]
twitlexU <- twitlex$coefficients[2,1] + twitlex$coefficients[2,2] * 1.96
twitlexL <- twitlex$coefficients[2,1] - twitlex$coefficients[2,2] * 1.96


## twitter vader
d$treat[d$date > -1] <- 1
d$treat[d$date < 0] <- 0
table(d$treat)
twitvad <- lm(compound ~ treat, data = d)
twitvad <- summary(twitvad)

# with politician fixed effects
twitvadfix <- lm(compound ~ treat + username, data = d)
twitvadfix <- summary(twitvadfix)

twitvadC <- twitvad$coefficients[2,1]
twitvadU <- twitvad$coefficients[2,1] + twitvad$coefficients[2,2] * 1.96
twitvadL <- twitvad$coefficients[2,1] - twitvad$coefficients[2,2] * 1.96


## factiva lexicoder
c3$treat[c3$tal > -1] <- 1
c3$treat[c3$tal < 0] <- 0
table(c3$treat)
faclex <- lm(sentiment ~ treat, data = c3)
faclex <- summary(faclex)

# with ideology fixed effects
faclexfix <- lm(sentiment ~ treat + ideology, data = c3)
faclexfix <- summary(faclexfix)

faclexC <- faclex$coefficients[2,1]
faclexU <- faclex$coefficients[2,1] + faclex$coefficients[2,2] * 1.96
faclexL <- faclex$coefficients[2,1] - faclex$coefficients[2,2] * 1.96


## factiva vader
d3$treat[d3$tal > -1] <- 1
d3$treat[d3$tal < 0] <- 0
table(d3$treat)
facvad <- lm(compound ~ treat, data = d3)
facvad <- summary(facvad)

# with ideology fixed effects
facvadfix <- lm(compound ~ treat + ideology, data = d3)
facvadfix <- summary(facvadfix)

facvadC <- facvad$coefficients[2,1]
facvadU <- facvad$coefficients[2,1] + facvad$coefficients[2,2] * 1.96
facvadL <- facvad$coefficients[2,1] - facvad$coefficients[2,2] * 1.96

texreg(l = list(twitlex, twitvad, faclex, facvad), include.ci = FALSE, digits = 3)


aplot1 <- ggplot(senti, aes(x = date, y = mean)) + 
  geom_line(size = 2, color = "slateblue4") +
  geom_point(aes(x = 0, y = twitlexC), size = 8) +
  geom_errorbar(aes(x = 0, ymin = twitlexL, ymax = twitlexU), size = 3) +
  geom_ribbon(aes(ymin = lower_green, ymax = upper_green), fill = "green", alpha = 0.5) +
  geom_ribbon(aes(ymin = lower_red, ymax = upper_red), fill = "red", alpha = 0.5) +
  xlab("Days") +
  ylab("Sentiment") +
  scale_x_continuous(breaks= c(-15, -10, -5, 0, 5, 10, 15)) +
  geom_vline(xintercept = 0, color = "black", linetype = "dashed", size = 1) +
  theme_light(base_size = 20) +
  ggtitle("A: Twitter Lexicoder")
aplot1


bplot1 <- ggplot(senti2, aes(x = date, y = mean)) + 
  geom_line(size = 2, color = "slateblue4") +
  geom_point(aes(x = 0, y = twitvadC), size = 8) +
  geom_errorbar(aes(x = 0, ymin = twitvadL, ymax = twitvadU), size = 3) +
  geom_ribbon(aes(ymin = lower_green, ymax = upper_green), fill = "green", alpha = 0.5) +
  geom_ribbon(aes(ymin = lower_red, ymax = upper_red), fill = "red", alpha = 0.5) +
  xlab("Days") +
  ylab("Sentiment") +
  scale_x_continuous(breaks= c(-15, -10, -5, 0, 5, 10, 15)) +
  geom_vline(xintercept = 0, color = "black", linetype = "dashed", size = 1) +
  theme_light(base_size = 25) +
  ggtitle("B: Twitter VADER")
bplot1 


cplot1 <- ggplot(senti3, aes(x = tal, y = mean)) + 
  geom_line(size = 2, color = "slateblue4") +
  geom_point(aes(x = 0, y = faclexC), size = 8) +
  geom_errorbar(aes(x = 0, ymin = faclexL, ymax = faclexU), size = 3) +
  geom_ribbon(aes(ymin = lower_green, ymax = upper_green), fill = "green", alpha = 0.5) +
  geom_ribbon(aes(ymin = lower_red, ymax = upper_red), fill = "red", alpha = 0.5) +
  xlab("Days") +
  ylab("Sentiment") +
  scale_x_continuous(breaks= c(-15, -10, -5, 0, 5, 10, 15)) +
  geom_vline(xintercept = 0, color = "black", linetype = "dashed", size = 1) +
  theme_light(base_size = 25) +
  ggtitle("C: Factiva Lexicoder")
cplot1


dplot1 <- ggplot(senti4, aes(x = tal, y = mean)) + 
  geom_line(size = 2, color = "slateblue4") +
  geom_point(aes(x = 0, y = facvadC), size = 8) +
  geom_errorbar(aes(x = 0, ymin = facvadL, ymax = facvadU), size = 3) +
  geom_ribbon(aes(ymin = lower_green, ymax = upper_green), fill = "green", alpha = 0.5) +
  geom_ribbon(aes(ymin = lower_red, ymax = upper_red), fill = "red", alpha = 0.5) +
  xlab("Days") +
  ylab("Sentiment") +
  scale_x_continuous(breaks= c(-15, -10, -5, 0, 5, 10, 15)) +
  geom_vline(xintercept = 0, color = "black", linetype = "dashed", size = 1) +
  theme_light(base_size = 25) +
  ggtitle("D: Factiva VADER")
dplot1

# topics
ggarrange(stmplot, seededldaplot, dictplot, factivaplot)


# sentiments
ggarrange(aplot1,bplot1,cplot1,dplot1)


# heterogeneity
ggarrange(prevbothplot, sentbothplot)




